package com.qzsf.backend.mapper;

import com.qzsf.backend.entity.UserAuth;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/10/30 16:46 周三
 * @Email 1429278462@qq.com
 * @Remark 用户登录信息数据访问层
 * @Version 1.0
 */
@Repository
@Mapper
public interface UserAuthMapper {
    @Select("select * from userauth where username = #{username}")
    UserAuth findByUsername(String username);

    @Select("select * from userauth")
    List<UserAuth> getAllUserAuth();

    @Select("select * from userauth where username like concat('%',#{username},'%')")
    List<UserAuth> getUserAuthByName(String username);

    @Select("select * from userauth where id = #{id}")
    UserAuth getUserAuthById(int id);

    @Delete("delete from userauth where id = #{id}")
    int deleteUserAuth(int id);

    @Update("update userauth set role = #{role},username = #{username},status = #{status},password = #{password} where id = #{id}")
    int updateUserAuth(UserAuth userAuth);

    @Insert("insert into userauth ( username, password, role, status) values (#{username},#{password},#{role},#{status}) ")
    int createUserAuth(UserAuth userAuth);

    @Select("select count(*) from userauth where role = 'USER'")
    int getUserNum();

    @Select("select * from userauth where username = #{username}")
    UserAuth getUserByName(String username);

    @Update("update userauth set password = #{newPassword} where username = #{username}")
    int forgetPassword(String username,String newPassword);
}
